package com.example.lee1.controller;

import com.example.lee1.entity.UserCollectionEntity;
import com.example.lee1.service.UserCollectionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-13 16:12:03
 */
@RestController
@RequestMapping("generator/usercollection")
public class UserCollectionController {
  @Autowired private UserCollectionService userCollectionService;

  /** 列表 */
  @RequestMapping("/list")
  @RequiresPermissions("generator:usercollection:list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = userCollectionService.queryPage(params);

    return R.ok().put("page", page);
  }

  /** 信息 */
  @RequestMapping("/info/{uid}")
  @RequiresPermissions("generator:usercollection:info")
  public R info(@PathVariable("uid") Integer uid) {
    UserCollectionEntity userCollection = userCollectionService.getById(uid);

    return R.ok().put("userCollection", userCollection);
  }

  /** 保存 */
  @RequestMapping("/save")
  @RequiresPermissions("generator:usercollection:save")
  public R save(@RequestBody UserCollectionEntity userCollection) {
    userCollectionService.save(userCollection);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  @RequiresPermissions("generator:usercollection:update")
  public R update(@RequestBody UserCollectionEntity userCollection) {
    userCollectionService.updateById(userCollection);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  @RequiresPermissions("generator:usercollection:delete")
  public R delete(@RequestBody Integer[] uids) {
    userCollectionService.removeByIds(Arrays.asList(uids));

    return R.ok();
  }
}
